import { getDetailsApi } from "@/api/client/documentManagement/advanceManagement";
import { computed, reactive, ref } from "vue";
import { formItemColumnMap } from "../data";
export default function InitHook() {
  const formState = ref<Partial<ClientAdvanceManagement.CilentInfo>>({});
  const loading = ref<boolean>(false);
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  const formItemColumn = computed<Array<{ name: string; label: string }>>(() => {
    return formItemColumnMap[formState.value.shippingMethod || 0] || [];
  });
  const init = async (id: string) => {
    loading.value = true;
    return getDetailsApi(id)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          formState.value = data;
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };
  return {
    formState,
    dialogOpts,
    init,
    loading,
    formItemColumn
  };
}
